<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
	</head>

	<body>
		
		<!-- 使用muiBody开发 -->
		<div class="mui-content">
			
			<!-- 使用mlist开发 -->
			<ul class="mui-table-view">
				<li class="mui-table-view-cell mui-media">
					<a id="link_myFace" href="javascript:;">
						<!-- 增加箭头 -->
						<span class="mui-pull-right mui-icon mui-icon-arrowright"
							style="line-height: 42px; color: lightgray;margin-left: 3px;"></span>
						<img id="img_my_face" class="mui-media-object mui-pull-right" src="">
						<div class="mui-media-body" style="line-height: 42px; font-size: 16px;">
							头像
						</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media">
					<a id="link_myNickname" href="javascript:;">
						<!-- 增加箭头 -->
						<span class="mui-pull-right mui-icon mui-icon-arrowright"
							style="color: lightgray;margin-left: 3px;"></span>
							<span id="span_nickname" class="mui-pull-right" style="color: gray;font-size: 14px;"></span>
						<div class="mui-media-body">
							昵称
						</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media">
					<a href="javascript:;">
						<span id="span_username" class="mui-pull-right" style="color: gray;font-size: 14px;"></span>
						<div class="mui-media-body">
						    账号
						</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media">
					<a id="my_qrcode" href="javascript:;">
						<!-- 增加箭头 -->
						<span class="mui-pull-right mui-icon mui-icon-arrowright"
							style=" color: lightgray;margin-left: 3px;"></span>
						<img class="mui-media-object mui-pull-right" src="image/qrcode.png" 
							style="max-width: 20px; height: 20px;">
						<div class="mui-media-body">
						    我的二维码
						</div>
					</a>
				</li>
			</ul>
			
			<br />
			
			<ul class="mui-table-view">
		    	<li class="mui-table-view-cell mui-media" 
		    		style="text-align: center;">
		            <a id="user_logout" href="javascript:;">
		                <div class="mui-media-body">
		                    退出登录
		                </div>
		            </a>
		        </li>
		    </ul>
			
		</div>
		
		<script src="js/mui.js"></script>
		<script src="js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			
			mui.plusReady(function () {
			    //获取当前webview对象,刷新当前用户信息
				var meWebview = plus.webview.currentWebview();
				//当显示该webview时,执行方法
				meWebview.addEventListener("show",function(){
					refreshUserInfo();
				})
				
				//点击头像栏时，弹出窗口,修改头像
				var link_myFace = document.getElementById("link_myFace");
				link_myFace.addEventListener("tap",function(){
					//弹出新的页面
					mui.openWindow("myFace.html","myFace.html");
				});
				
				//点击头像栏时，弹出窗口,修改头像
				var link_myFace = document.getElementById("link_myFace");
				link_myFace.addEventListener("tap",function(){
					//弹出新的页面
					mui.openWindow("myFace.html","myFace.html");
				});
				
				//点击昵称栏时，弹出窗口,修改头像昵称
				var link_myNickname = document.getElementById("link_myNickname");
				link_myNickname.addEventListener("tap",function(){
					//弹出新的页面
					mui.openWindow("myNickname.html","myNickname.html");
				});
				
				//点击二维码栏时，弹出窗口
				var my_qrcode = document.getElementById("my_qrcode");
				my_qrcode.addEventListener("tap",function(){
					//弹出新的页面
					mui.openWindow("myQRCode.html","myQRCode.html");
				});
				
				//添加自定义事件, 刷新用户的头像
				window.addEventListener("refresh",function(){
					refreshUserInfo();
				});
				
				//用户退出
				var user_logout = document.getElementById("user_logout");
				user_logout.addEventListener("tap",function(){
					app.userLogout();
					//清空indexWebview,保证重新登录后可以刷新用户信息					
					mui.openWindow("login.html","login.html");
					setTimeout("closeIndex()",500);
				})
			});
			
			function refreshUserInfo(){
				var user = app.getUserGlobalInfo();
				//打印用户信息
				console.log("登录的个人信息为：" + JSON.stringify(user));
				
				if(user != null){
					var username = user.username;
					var nickname = user.nickname;
					var faceImage = user.faceImage;
					var faceImageBig = user.faceImageBig;
					
					//获取dom对象，渲染用户数据
					var span_nickname =  document.getElementById("span_nickname");
					var span_username =  document.getElementById("span_username");
					
					span_nickname.innerHTML = nickname;
					span_username.innerHTML = username;
					
					//处理用户头像
					if(app.isNotNull(faceImage)){
						var img_my_face = document.getElementById("img_my_face");
						img_my_face.src = app.imgServerUrl + faceImage;
					}
				}
			}
			
			function closeIndex(){
				plus.webview.close("index.html","none",0,"auto");
			}
			
		</script>
	</body>

</html>
